import 'package:casdon/common/widget/common_banner_widget.dart';
import 'package:casdon/core/utils/list_externtion.dart';
import 'package:casdon/modules/recipe/data/model/recipe_module_content_model.dart';
import 'package:casdon/modules/recipe/domain/states/recipe_module_content_state.dart';
import 'package:casdon/auto_router.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class RecipeModuleStyle3Content extends StatelessWidget {
  final RecipeModuleContentState state;
  const RecipeModuleStyle3Content({super.key, required this.state});

  @override
  Widget build(BuildContext context) {
    List<RecipeModuleContentModel> list = state.data.takeFirstN(5);
    List<String> listImgUrl = list
        .where((item) => item.imgUrl != null)
        .map((item) => item.imgUrl!)
        .toList();

    List<String> listUrl = list
        .where((item) => item.url != null)
        .map((item) => item.url!)
        .toList();

    return CommonBannerWidget(
      imageUrls: listImgUrl,
      height: 110.h,
      onTap: (index) => {
        WebPageRoute(url: listUrl[index], title: '').push(context),
      },
    );
  }
}

class RecipeModuleStyle3ContentV extends StatelessWidget {
  final RecipeModuleContentState state;
  const RecipeModuleStyle3ContentV({super.key, required this.state});

  @override
  Widget build(BuildContext context) {
    if (state.data.isEmpty) {
      return const SizedBox.shrink();
    }

    return SizedBox(
      height: 128.h,
      child: ListView.builder(
        scrollDirection: Axis.horizontal,
        padding: EdgeInsets.symmetric(horizontal: 12.w),
        itemCount: state.data.length,
        itemBuilder: (context, index) {
          final item = state.data[index];
          // return RecipeCardStyle1(item: item);
          return SizedBox(width: 12);
        },
      ),
    );
  }
}
